//
//  ProjectWindow.cpp
//  Editor
//
//  Created by Jeppe Nielsen on 10/19/14.
//  Copyright (c) 2014 Jeppe Nielsen. All rights reserved.
//

#include "ProjectWindow.hpp"


ProjectWindow::ProjectWindow() {

    QVBoxLayout* mainLayout = new QVBoxLayout();

    QGroupBox* projectGroupbox = new QGroupBox(tr("Create new project"));
    QVBoxLayout* projectGroupLayout = new QVBoxLayout();
    projectGroupbox->setLayout(projectGroupLayout);
    
        QGroupBox* projectPathBox = new QGroupBox(tr("Project location"));
        QHBoxLayout* projectPathLayout = new QHBoxLayout();
        projectPathBox->setLayout(projectPathLayout);
    
            projectPath = new QLineEdit();
            QPushButton* pathButton = new QPushButton();
            pathButton->setText("^");
            connect(pathButton, SIGNAL(clicked()), this, SLOT(DirectoryButtonClicked()));
    
            projectPathLayout->addWidget(projectPath);
            projectPathLayout->addWidget(pathButton);
    
    QPushButton* createProjectButton = new QPushButton();
    createProjectButton->setText("Create");
    connect(createProjectButton, SIGNAL(clicked()), this, SLOT(CreateButtonClicked()));
    
    
    projectGroupLayout->addWidget(projectPathBox);
    projectGroupLayout->addWidget(createProjectButton);

    mainLayout->addWidget(projectGroupbox);
    
    setLayout(mainLayout);
}

void ProjectWindow::DirectoryButtonClicked() {

QFileDialog::Options options = 0;
    options |= QFileDialog::DontResolveSymlinks | QFileDialog::ShowDirsOnly;
    QString directory = QFileDialog::getExistingDirectory(this,
                                tr("QFileDialog::getExistingDirectory()"),
                                projectPath->text(),
                                options);
    if (!directory.isEmpty())
        projectPath->setText(directory);
}

void ProjectWindow::CreateButtonClicked() {
    close();
    ProjectCreated(projectPath->text());
}